<!DOCTYPE html>
<html lang="Chinese, English">
<head>

    <!--[if lt IE 9]>
        <style>body {display: none; background: none !important} </style>
        <meta http-equiv="Refresh" Content="0; url=//outdatedbrowser.com/" />
    <![endif]-->

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="format-detection" content="telephone=no" />
<meta name="author" content="Green" />



<meta name="description" content="饼状图是数据统计中经常用到的另一类图表，饼图可以直观地显示一个数据系列中各项的大小与各项总和的比例，本文将使用D3上手制作一个简单的饼状图">
<meta property="og:type" content="article">
<meta property="og:title" content="D3.js上手——饼状图">
<meta property="og:url" content="https://greenmzc.github.io/2016/11/07/D3-js上手——饼状图/index.html">
<meta property="og:site_name" content="Green的博客 | Green's Blog">
<meta property="og:description" content="饼状图是数据统计中经常用到的另一类图表，饼图可以直观地显示一个数据系列中各项的大小与各项总和的比例，本文将使用D3上手制作一个简单的饼状图">
<meta property="og:image" content="https://greenmzc.github.io/img/2016110701.png">
<meta property="og:image" content="https://greenmzc.github.io/img/2016110702.png">
<meta property="og:image" content="https://greenmzc.github.io/img/2016110703.png">
<meta property="og:image" content="https://greenmzc.github.io/img/2016110704.png">
<meta property="og:image" content="https://greenmzc.github.io/img/2016110705.png">
<meta property="og:updated_time" content="2017-02-14T03:45:28.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="D3.js上手——饼状图">
<meta name="twitter:description" content="饼状图是数据统计中经常用到的另一类图表，饼图可以直观地显示一个数据系列中各项的大小与各项总和的比例，本文将使用D3上手制作一个简单的饼状图">
<meta name="twitter:image" content="https://greenmzc.github.io/img/2016110701.png">

<link rel="apple-touch-icon" href= "/apple-touch-icon.png">


    <link rel="alternate" href="/atom.xml" title="Green的博客 | Green&#39;s Blog" type="application/atom+xml">



    <link rel="shortcut icon" href="/favicon.png">



    <link href="//cdn.bootcss.com/animate.css/3.5.1/animate.min.css" rel="stylesheet">



    <link href="//cdn.bootcss.com/fancybox/2.1.5/jquery.fancybox.min.css" rel="stylesheet">



    <script src="//cdn.bootcss.com/pace/1.0.2/pace.min.js"></script>
    <link href="//cdn.bootcss.com/pace/1.0.2/themes/green/pace-theme-minimal.css" rel="stylesheet">


<link rel="stylesheet" href="/css/style.css">



<link href="//cdn.bootcss.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet">


<title>D3.js上手——饼状图 | Green的博客 | Green&#39;s Blog</title>

<script src="//cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script>
<script src="//cdn.bootcss.com/clipboard.js/1.5.10/clipboard.min.js"></script>

<script>
    var yiliaConfig = {
        fancybox: true,
        animate: true,
        isHome: false,
        isPost: true,
        isArchive: false,
        isTag: false,
        isCategory: false,
        fancybox_js: "//cdn.bootcss.com/fancybox/2.1.5/jquery.fancybox.min.js",
        scrollreveal: "//cdn.bootcss.com/scrollReveal.js/3.1.4/scrollreveal.min.js",
        search: undefined
    }
</script>


    <script> yiliaConfig.jquery_ui = [false]; </script>



    <script> yiliaConfig.rootUrl = "\/";</script>



    <script src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-56ff76c972fc0cf9"></script>



    <script>
        var _hmt = _hmt || [];
        (function() {
            var hm = document.createElement("script");
            hm.src = "//hm.baidu.com/hm.js?74f5c9dc68aa8b1babf7bd3c11285f9b";
            var s = document.getElementsByTagName("script")[0]; 
            s.parentNode.insertBefore(hm, s);
        })();
    </script>


</head>
<body>
  <div id="container">
    <div class="left-col">
    <div class="overlay"></div>
<div class="intrude-less">
    <header id="header" class="inner">
        <a href="/" class="profilepic">
            <img src="/img/avatar.png" class="animated zoomIn">
        </a>
        <hgroup>
          <h1 class="header-author"><a href="/">Green</a></h1>
        </hgroup>

        

        


        
            <div id="switch-btn" class="switch-btn">
                <div class="icon">
                    <div class="icon-ctn">
                        <div class="icon-wrap icon-house" data-idx="0">
                            <div class="birdhouse"></div>
                            <div class="birdhouse_holes"></div>
                        </div>
                        <div class="icon-wrap icon-ribbon hide" data-idx="1">
                            <div class="ribbon"></div>
                        </div>
                        
                        <div class="icon-wrap icon-link hide" data-idx="2">
                            <div class="loopback_l"></div>
                            <div class="loopback_r"></div>
                        </div>
                        
                        
                        <div class="icon-wrap icon-me hide" data-idx="3">
                            <div class="user"></div>
                            <div class="shoulder"></div>
                        </div>
                        
                    </div>
                    
                </div>
                <div class="tips-box hide">
                    <div class="tips-arrow"></div>
                    <ul class="tips-inner">
                        <li>菜单</li>
                        <li>标签</li>
                        
                        <li>友情链接</li>
                        
                        
                        <li>关于我</li>
                        
                    </ul>
                </div>
            </div>
        

        <div id="switch-area" class="switch-area">
            <div class="switch-wrap">
                <section class="switch-part switch-part1">
                    <nav class="header-menu">
                        <ul>
                        
                            <li><a href="/">主页</a></li>
                        
                            <li><a href="/archives/">所有文章</a></li>
                        
                        </ul>
                    </nav>
                    <nav class="header-nav">
                        <ul class="social">
                            
                                <a class="fa Email" href="mailto:15869186780@163.com" title="Email"></a>
                            
                                <a class="fa GitHub" href="https://github.com/Greenmzc" title="GitHub"></a>
                            
                        </ul>
                    </nav>
                </section>
                
                
                <section class="switch-part switch-part2">
                    <div class="widget tagcloud" id="js-tagcloud">
                        <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/tags/D3/">D3</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/JavaScript/">JavaScript</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/blog/">blog</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/css/">css</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/shell/">shell</a></li></ul>
                    </div>
                </section>
                
                
                
                <section class="switch-part switch-part3">
                    <div id="js-friends">
                    
                      <a class="main-nav-link switch-friends-link" href="http://fangyi.me">Phieo</a>
                    
                      <a class="main-nav-link switch-friends-link" href="https://excaliburhan.com">虚夜宫</a>
                    
                      <a class="main-nav-link switch-friends-link" href="http://www.ggfly.me">郁川溪畔</a>
                    
                      <a class="main-nav-link switch-friends-link" href="https://nickliuyong.github.io/blogs/">NickLiu</a>
                    
                      <a class="main-nav-link switch-friends-link" href="http://blog.icdoit.com">没事溜达</a>
                    
                      <a class="main-nav-link switch-friends-link" href="http://www.lixuejiang.me">风君子</a>
                    
                    </div>
                </section>
                

                
                
                <section class="switch-part switch-part4">
                
                    <div id="js-aboutme">专注于前端</div>
                </section>
                
            </div>
        </div>
    </header>                
</div>
    </div>
    <div class="mid-col">
      <nav id="mobile-nav">
      <div class="overlay">
          <div class="slider-trigger"></div>
          <h1 class="header-author js-mobile-header hide"><a href="/" title="回到主页">Green</a></h1>
      </div>
    <div class="intrude-less">
        <header id="header" class="inner">
            <a href="/" class="profilepic">
                <img src="/img/avatar.png" class="animated zoomIn">
            </a>
            <hgroup>
              <h1 class="header-author"><a href="/" title="回到主页">Green</a></h1>
            </hgroup>
            
            <nav class="header-menu">
                <ul>
                
                    <li><a href="/">主页</a></li>
                
                    <li><a href="/archives/">所有文章</a></li>
                
                <div class="clearfix"></div>
                </ul>
            </nav>
            <nav class="header-nav">
                        <ul class="social">
                            
                                <a class="fa Email" target="_blank" href="mailto:15869186780@163.com" title="Email"></a>
                            
                                <a class="fa GitHub" target="_blank" href="https://github.com/Greenmzc" title="GitHub"></a>
                            
                        </ul>
            </nav>
        </header>                
    </div>
    <link class="menu-list" tags="标签" friends="友情链接" about="关于我"/>
</nav>
      <div class="body-wrap"><article id="post-D3-js上手——饼状图" class="article article-type-post" itemscope itemprop="blogPost">
  
    <div class="article-meta">
      <a href="/2016/11/07/D3-js上手——饼状图/" class="article-date">
      <time datetime="2016-11-07T09:29:27.000Z" itemprop="datePublished">2016-11-07</time>
</a>


    </div>
  
  <div class="article-inner">
    
      <input type="hidden" class="isFancy" />
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      D3.js上手——饼状图
    </h1>
  

      </header>
      
      <div class="article-info article-info-post">
        

        
    <div class="article-tag tagcloud">
        <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/D3/">D3</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/JavaScript/">JavaScript</a></li></ul>
    </div>

        <div class="clearfix"></div>
      </div>
      
    
    <div class="article-entry" itemprop="articleBody">
      
          
        <p>饼状图是数据统计中经常用到的另一类图表，饼图可以直观地显示一个数据系列中各项的大小与各项总和的比例，本文将使用D3上手制作一个简单的饼状图</p>
<a id="more"></a>
<h3 id="什么是布局"><a href="#什么是布局" class="headerlink" title="什么是布局"></a>什么是布局</h3><p>布局是D3中非常重要的内容，有了布局D3才能画出复杂的矢量图。但布局并不是直接绘制图形，只是将初始数据转换成容易画图的图形语言，画图工具能读懂图形语言来进行绘制。</p>
<p>在绘制饼状图中，例如有一组数据[1, 2, 3]，只依靠这些数据是画不出的，需要将这些数据转化为圆形的起始角度和终止角度，第一块的角度区域为[0, π/3]，第二块的角度区域为[π/3, π]……绘制工具能根据这些角度值进行绘制。<code>布局只进行数据转换</code></p>
<p>D3还提供其他常用图表的布局函数，比如<code>力导向图</code>(Force)、<code>弦图</code>(Chord)、<code>树状图</code>(Tree)、<code>直方图</code>(Histogram)、<code>分区图</code>(Partition)等，每种布局有对应的API</p>
<h3 id="确定数据"><a href="#确定数据" class="headerlink" title="确定数据"></a>确定数据</h3><p>表格数据是来自<a href="http://www.w3schools.com/browsers/" target="_blank" rel="external">w3schools</a>的2016年9月的浏览器使用率</p>
<table>
<thead>
<tr>
<th style="text-align:center">浏览器</th>
<th style="text-align:center">占比</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center">Chrome</td>
<td style="text-align:center">72.5%</td>
</tr>
<tr>
<td style="text-align:center">IE</td>
<td style="text-align:center">5.3%</td>
</tr>
<tr>
<td style="text-align:center">Firefox</td>
<td style="text-align:center">16.3%</td>
</tr>
<tr>
<td style="text-align:center">Safari</td>
<td style="text-align:center">3.5%</td>
</tr>
<tr>
<td style="text-align:center">Opera</td>
<td style="text-align:center">1.0%</td>
</tr>
<tr>
<td style="text-align:center">Others</td>
<td style="text-align:center">1.4%</td>
</tr>
</tbody>
</table>
<p>对此设定以下二维数组装载这些数据</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> dataset = [[<span class="string">'Chrome'</span>, <span class="number">72.5</span>], [<span class="string">'IE'</span>, <span class="number">5.3</span>], [<span class="string">'Firefox'</span>, <span class="number">16.3</span>], [<span class="string">'Safari'</span>, <span class="number">3.5</span>], [<span class="string">'Opera'</span>, <span class="number">1.0</span>], [<span class="string">'Others'</span>, <span class="number">1.4</span>]];</div></pre></td></tr></table></figure>
<h3 id="建立布局"><a href="#建立布局" class="headerlink" title="建立布局"></a>建立布局</h3><ul>
<li><code>d3.pie()</code> 构造一个新的饼布局</li>
</ul>
<p>构建一个饼布局并接收数据</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> pie = d3.pie()</div><div class="line">            .sort(<span class="literal">null</span>) <span class="comment">// 在创建布局的时候，默认排序数据从大到小，设为null可以按照数组默认顺序排序</span></div><div class="line">            .value(<span class="function"><span class="keyword">function</span>(<span class="params">d</span>)</span>&#123;</div><div class="line">              <span class="keyword">return</span> d[<span class="number">1</span>]</div><div class="line">            &#125;);</div></pre></td></tr></table></figure>
<p>把数据转换为饼图绘制所需要的数据</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> piedata = pie(dataset);</div><div class="line"><span class="built_in">console</span>.log(piedata);</div></pre></td></tr></table></figure>
<p>在控制台输出piedata，看看转换后的数据</p>
<img src="/img/2016110701.png" width="250" height="380" title="2016110701">
<p>可以看到，原来的数据已经被转换成6组适合画图的数据</p>
<ul>
<li><code>data</code> —— 保留原有数据</li>
<li><code>index</code> —— 序号</li>
<li><code>startAngle</code> —— 一段弧的起始角度</li>
<li><code>endAngle</code> —— 一段弧的终止角度</li>
</ul>
<h3 id="生成弧生成器"><a href="#生成弧生成器" class="headerlink" title="生成弧生成器"></a>生成弧生成器</h3><p>虽然有了角度，但目前还是很难画出我们想要的饼图，还要用到D3中的路径生成器。在svg中，path标签的路径数值往往十分复杂，手动去生成是不现实的，尤其是要生成各种复杂曲线的时候，好在D3提供了基本的路径生成器，有线段、区域、弧生成器等。画饼图的时候需要用到弧生成器，帮助我们把转换后的数据真正绘制出来</p>
<ul>
<li><code>d3.arc()</code> 创建一个新的弧生成器</li>
<li><code>arc.innerRadius([radius])</code> 设置内部半径</li>
<li><code>arc.outerRadius([radius])</code> 设置外部半径</li>
</ul>
<p>这里把画布的四分之一作为外部半径，内部半径设为0就是饼图，没错，设置大于0就是圆环图</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> outerRadius = width / <span class="number">4</span>;</div><div class="line"><span class="keyword">var</span> innerRadius = <span class="number">0</span>;</div><div class="line"><span class="keyword">var</span> arc = d3.arc()</div><div class="line">            .outerRadius(outerRadius)</div><div class="line">            .innerRadius(innerRadius);</div></pre></td></tr></table></figure>
<h3 id="绘制饼图"><a href="#绘制饼图" class="headerlink" title="绘制饼图"></a>绘制饼图</h3><p>跟之前一样，创建g组合标签后，把piedata数据绑定至g标签，这里要用到D3的内置颜色，<code>d3.schemeCategory10</code>选了10种颜色，方便我们随时使用，为饼图的不同区域填色，不必为想不出好的颜色搭配而烦恼，当然也可以自定义颜色</p>
<img src="/img/2016110702.png" width="500" height="100" title="2016110702">
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> arcs = svg.selectAll(<span class="string">'g'</span>)</div><div class="line">              .data(piedata)</div><div class="line">              .enter()</div><div class="line">              .append(<span class="string">'g'</span>)</div><div class="line">              .attr(<span class="string">'transform'</span>, <span class="string">'translate('</span> + width / <span class="number">2</span> + <span class="string">','</span> + height / <span class="number">2</span> + <span class="string">')'</span>);</div><div class="line"><span class="comment">// 调用内置颜色序列</span></div><div class="line"><span class="keyword">var</span> colors = d3.schemeCategory10;</div><div class="line">arcs.append(<span class="string">'path'</span>)</div><div class="line">    .attr(<span class="string">'fill'</span>, <span class="function"><span class="keyword">function</span>(<span class="params">d, i</span>)</span>&#123;</div><div class="line">      <span class="keyword">return</span> colors[i];</div><div class="line">    &#125;)</div><div class="line">    .attr(<span class="string">'d'</span>, <span class="function"><span class="keyword">function</span>(<span class="params">d</span>)</span>&#123;</div><div class="line">      <span class="keyword">return</span> arc(d);</div><div class="line">    &#125;);</div></pre></td></tr></table></figure>
<p>在path标签中，给d属性赋予数据经过弧生成器处理的值，这样一个没有标注的饼图就完成了</p>
<img src="/img/2016110703.png" width="300" height="300" title="2016110703">
<h3 id="添加标注"><a href="#添加标注" class="headerlink" title="添加标注"></a>添加标注</h3><ul>
<li><code>arc.centroid(arguments…)</code> 获取弧中心坐标</li>
</ul>
<p>接下来给饼图加一些标注，以便更好地阅读图形，主要用到弧中心的概念，如下图，黑点就是每个弧的中心，利用<code>arc.centroid()</code>可以获取弧中心的坐标，并且这个坐标是相对圆形的相对坐标。有了这个坐标，可以很方便地在每个弧上添加文字标注</p>
<img src="/img/2016110704.png" width="260" height="260" title="2016110704">
<p><code>arc.centroid(d)</code>是一个包含横坐标和纵坐标的数组<code>[x, y]</code>，给坐标乘以2倍以上的数值就把文字移到圆形外边</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line">arcs.append(<span class="string">'text'</span>)</div><div class="line">    .attr(<span class="string">'transform'</span>, <span class="function"><span class="keyword">function</span>(<span class="params">d, i</span>)</span>&#123;</div><div class="line">      <span class="keyword">var</span> x = arc.centroid(d)[<span class="number">0</span>] * <span class="number">2.8</span>;</div><div class="line">      <span class="keyword">var</span> y = arc.centroid(d)[<span class="number">1</span>] * <span class="number">2.8</span>;</div><div class="line">      <span class="keyword">return</span> <span class="string">'translate('</span> + x + <span class="string">', '</span> + y + <span class="string">')'</span>;</div><div class="line">    &#125;)</div><div class="line">    .attr(<span class="string">'text-anchor'</span>, <span class="string">'middle'</span>)</div><div class="line">    .text(<span class="function"><span class="keyword">function</span>(<span class="params">d</span>)</span>&#123;</div><div class="line">      <span class="keyword">var</span> percent = <span class="built_in">Number</span>(d.value) / d3.sum(dataset, <span class="function"><span class="keyword">function</span>(<span class="params">d</span>)</span>&#123;</div><div class="line">        <span class="keyword">return</span> d[<span class="number">1</span>];</div><div class="line">      &#125;) * <span class="number">100</span>;</div><div class="line">      <span class="keyword">return</span> d.data[<span class="number">0</span>] + <span class="string">' '</span> + percent.toFixed(<span class="number">1</span>) + <span class="string">'%'</span>;</div><div class="line">    &#125;)</div></pre></td></tr></table></figure>
<p>最后再加一些连线</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line">arcs.append(<span class="string">'line'</span>)</div><div class="line">    .attr(<span class="string">'stroke'</span>, <span class="string">'black'</span>)</div><div class="line">    .attr(<span class="string">'x1'</span>, <span class="function"><span class="keyword">function</span>(<span class="params">d</span>)</span>&#123; <span class="keyword">return</span> arc.centroid(d)[<span class="number">0</span>] * <span class="number">2</span>; &#125;)</div><div class="line">    .attr(<span class="string">'y1'</span>, <span class="function"><span class="keyword">function</span>(<span class="params">d</span>)</span>&#123; <span class="keyword">return</span> arc.centroid(d)[<span class="number">1</span>] * <span class="number">2</span>; &#125;)</div><div class="line">    .attr(<span class="string">'x2'</span>, <span class="function"><span class="keyword">function</span>(<span class="params">d, i</span>)</span>&#123;</div><div class="line">      <span class="keyword">return</span> arc.centroid(d)[<span class="number">0</span>] * <span class="number">2.5</span>;</div><div class="line">    &#125;)</div><div class="line">    .attr(<span class="string">'y2'</span>, <span class="function"><span class="keyword">function</span>(<span class="params">d, i</span>)</span>&#123;</div><div class="line">      <span class="keyword">return</span> arc.centroid(d)[<span class="number">1</span>] * <span class="number">2.5</span>;</div><div class="line">    &#125;);</div></pre></td></tr></table></figure>
<p>由于最后几个数据太小，标注文字会重叠到一起，这里做了一个判断处理来错开数据值较小的文字，最后的效果图如下所示</p>
<img src="/img/2016110705.png" width="456" height="429" title="2016110705">
<p><a href="http://codepen.io/greenmzc/pen/JRwNpr/" target="_blank" rel="external">查看完整示例代码</a></p>

      
    </div>
    
  </div>
  
    


    <nav id="article-nav">
        
            <div id="article-nav-newer" class="article-nav-title">
                <a href="/2016/12/14/CSS背景渐变/">
                    CSS背景渐变
                </a>
            </div>
        
        
            <div id="article-nav-older" class="article-nav-title">
                <a href="/2016/10/18/D3-js上手——折线图/">
                    D3.js上手——折线图
                </a>
            </div>
        
    </nav>

  
</article>

    <div id="toc" class="toc-article">
        <strong class="toc-title">文章目录</strong>
        
            <ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#什么是布局"><span class="toc-number">1.</span> <span class="toc-text">什么是布局</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#确定数据"><span class="toc-number">2.</span> <span class="toc-text">确定数据</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#建立布局"><span class="toc-number">3.</span> <span class="toc-text">建立布局</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#生成弧生成器"><span class="toc-number">4.</span> <span class="toc-text">生成弧生成器</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#绘制饼图"><span class="toc-number">5.</span> <span class="toc-text">绘制饼图</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#添加标注"><span class="toc-number">6.</span> <span class="toc-text">添加标注</span></a></li></ol>
        
    </div>
    <style>
        .left-col .switch-btn,
        .left-col .switch-area {
            display: none;
        }
        .toc-level-3 i,
        .toc-level-3 ol {
            display: none !important;
        }
    </style>

    <input type="button" id="tocButton" value="隐藏目录"  title="点击按钮隐藏或者显示文章目录">

    <script>
        yiliaConfig.toc = ["隐藏目录", "显示目录", !!"false"];
    </script>



    
<div class="share">
    

    
        <div class="addthis_sharing_toolbox"></div>
    
</div>




    
      <div class="duoshuo" id="comments">
    <div id="comment-box" ></div>
    <div class="ds-thread" id="ds-thread" data-thread-key="2016/11/07/D3-js上手——饼状图/" data-title="D3.js上手——饼状图" data-url="https://greenmzc.github.io/2016/11/07/D3-js上手——饼状图/"></div>
    <script>
        var duoshuoQuery = {short_name:"greenmzc"};
        var loadComment = function(){
            var d = document, s = d.createElement('script');
            s.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
            s.async = true; s.charset = 'UTF-8';
            (d.head || d.body).appendChild(s);
        }

        
    </script>
    
    <script> loadComment(); </script>

</div>
    




    <div class="scroll" id="post-nav-button">
        
            <a href="/2016/12/14/CSS背景渐变/" title="上一篇: CSS背景渐变">
                <i class="fa fa-angle-left"></i>
            </a>
        

        <a title="文章列表"><i class="fa fa-bars"></i><i class="fa fa-times"></i></a>

        
            <a href="/2016/10/18/D3-js上手——折线图/" title="下一篇: D3.js上手——折线图">
                <i class="fa fa-angle-right"></i>
            </a>
        
    </div>

    <ul class="post-list"><li class="post-list-item"><a class="post-list-link" href="/2016/12/14/CSS背景渐变/">CSS背景渐变</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/11/07/D3-js上手——饼状图/">D3.js上手——饼状图</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/10/18/D3-js上手——折线图/">D3.js上手——折线图</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/10/11/D3-js入门/">D3.js入门</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/10/06/开始使用hexo搭建博客/">开始使用hexo搭建博客</a></li></ul>




    <script>
        
    </script>

</div>
      <footer id="footer">
    <div class="outer">
        <div id="footer-info">
            <div class="footer-left">
                <i class="fa fa-copyright"></i>
                2016-2017 Green
            </div>
            <div class="footer-right">
                <a href="http://hexo.io/" target="_blank" title="快速、简洁且高效的博客框架">Hexo</a>  Theme <a href="https://github.com/MOxFIVE/hexo-theme-yelee" target="_blank" title="简而不减 Hexo 双栏博客主题  v3.5">Yelee</a> by MOxFIVE <i class="fa fa-heart animated infinite pulse"></i>
            </div>
        </div>
        
            <div class="visit">
                
                    <span id="busuanzi_container_site_pv" style='display:none'>
                        <span id="site-visit" title="本站到访数"><i class="fa fa-user" aria-hidden="true"></i><span id="busuanzi_value_site_uv"></span>
                        </span>
                    </span>
                
                
                    <span>| </span>
                
                
                    <span id="busuanzi_container_page_pv" style='display:none'>
                        <span id="page-visit"  title="本页阅读量"><i class="fa fa-eye animated infinite pulse" aria-hidden="true"></i><span id="busuanzi_value_page_pv"></span>
                        </span>
                    </span>
                
            </div>
        
    </div>
</footer>

    </div>
    
<script data-main="/js/main.js" src="//cdn.bootcss.com/require.js/2.2.0/require.min.js"></script>





<div class="scroll" id="scroll">
    <a href="#" title="返回顶部"><i class="fa fa-arrow-up"></i></a>
    <a href="#comments" onclick="load$hide();" title="查看评论"><i class="fa fa-comments-o"></i></a>
    <a href="#footer" title="转到底部"><i class="fa fa-arrow-down"></i></a>
</div>
<script>
    // Open in New Window
    
        var oOpenInNew = {
            
            
            
            
            
            
             archives: ".archive-article-title", 
             miniArchives: "a.post-list-link", 
            
             friends: "#js-friends a", 
             socail: ".social a" 
        }
        for (var x in oOpenInNew) {
            $(oOpenInNew[x]).attr("target", "_blank");
        }
    
</script>

<script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js">
</script>
  </div>
</body>
</html>